var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r, s = t("GlobalUserData"),
l = t("ConfirmRewardPanel"),
c = t("HallCarTotalView"),
d = t("HallConstant"),
h = t("HallScene"),
p = t("BroadCastMessage"),
u = t("Util"),
f = t("Bounce"),
m = t("Particle"),
_ = t("Global"),
y = t("StorageManager"),
g = t("BaseStorage"),
v = t("DailyTask"),
C = t("DailyTaskBox"); (function(t) {
    t[t.lottery = 0] = "lottery",
    t[t.victory = 1] = "victory",
    t[t.sell = 2] = "sell"
})(r || (r = {}));
var b = cc._decorator,
w = b.ccclass,
S = b.property,
I = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.taskType = r.lottery,
        e.progress = null,
        e.titleLabel = null,
        e.valueLabel = null,
        e.progressLabel = null,
        e.iconSpr = null,
        e.prefab = null,
        e.btnNode = null,
        e.pfb_boxView = null,
        e.node_finishBtn = null,
        e.statusNode = null,
        e.dailyTaskBox = null,
        e.dailyTask = null,
        e.value = 0,
        e.totalProgress = 0,
        e.obj = {
            a: 0
        },
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        switch (this.btn = this.btnNode.getComponent(cc.Button), this.taskType) {
            case r.lottery:
                this.storageKey = _.RedPointKey[_.RedPointKey.DailyTaskLotter];
            break;
            case r.victory:
                this.storageKey = _.RedPointKey[_.RedPointKey.DailyTaskVictory];
            break;
            case r.sell:
                this.storageKey = _.RedPointKey[_.RedPointKey.DailyTaskComponent];
        }
        cc.log("key:" + this.storageKey),
        y.StorageManager.setDailyTaskStorageKey(this.storageKey),
        this.receiveStatus(!1)
    },
    e.prototype.start = function() {
        if (this.valueLabel.node.addComponent(f.default).init(1, this.value, "X"), this.node.scale = 0, cc.tween(this.node).to(.5, {
            scale: 1
        },
        {
            easing: "elasticOut"
        }).start(), g.BaseStorage.getInt(this.storageKey, 0)) this.receiveStatus(!0);
        else switch (this.taskType) {
            case r.lottery:
                this.setProgress(g.BaseStorage.getInt(_.BaseStorageKey.UpgradeNumber, 0));
            break;
            case r.victory:
                this.setProgress(s.default.getDayWin());
            break;
            case r.sell:
                this.setProgress(g.BaseStorage.getInt(_.BaseStorageKey.GetBoxNumber, 0));
        }
    },
    e.prototype.onBtnToFinish = function() {
        switch (this.taskType) {
            case r.lottery:
                cc.find("Canvas").getChildByName("car").getComponent(c.default).onBtnAssembly(0, 0),
            this.dailyTask.close();
            break;
            case r.victory:
                this.dailyTask.close();
            break;
            case r.sell:
                cc.find("Canvas").getComponent(h.default).onBtnShop(),
            this.dailyTask.close();
        }
    },
    e.prototype.setProgress = function(t) {
        if (void 0 === t && (t = 0), t >= this.totalProgress) {
            t = this.totalProgress,
            this.btn.node.active = !0,
            this.node_finishBtn.active = !1;
            var e = g.BaseStorage.getInt(_.BaseStorageKey.RedDotDailyTask, 0) + 1;
            g.BaseStorage.setInt(_.BaseStorageKey.RedDotDailyTask, e)
        } else this.btn.node.active = !1,
        this.node_finishBtn.active = !0;
        this.progressLabel.string = t + "/" + this.totalProgress,
        this.progress.progress = t / this.totalProgress
    },
    e.prototype.receiveStatus = function(t) {
        this.statusNode.active = t,
        this.progress.node.active = !t,
        this.btnNode.active = !t,
        this.node_finishBtn.active = !t
    },
    e.prototype.getDateString = function() {
        return new Date().toDateString()
    },
    e.prototype.receiveClick = function() {
        var t = this;
        switch (p.default.getInstance().SendMessage(d.Broadcast_Func.Audio, d.Audio_ID.btn_click), g.BaseStorage.setInt(this.storageKey, 1), this.receiveStatus(!0), this.dailyTaskBox.increase(), this.taskType) {
            case r.lottery:
                u.Util.showConfirmPanel([{
                type:
                    l.rewardType.gold,
                num: this.value
            }],
            function() {
                s.default.saveGoldData(!0, t.value),
                cc.find("Canvas").getComponent(h.default).onSetOwnGold(!0),
                t.action()
            },
            !0,
            function() {
                s.default.saveGoldData(!0, 2 * t.value),
                cc.find("Canvas").getComponent(h.default).onSetOwnGold(!0),
                t.action()
            });
            break;
            case r.victory:
            case r.sell:
                u.Util.showConfirmPanel([{
                type:
                    l.rewardType.diamond,
                num: this.value
            }],
            function() {
                s.default.saveDiamondData(!0, t.value),
                cc.find("Canvas").getComponent(h.default).onSetOwnDiamond(!0),
                t.action()
            },
            !0,
            function() {
                s.default.saveDiamondData(!0, 2 * t.value),
                cc.find("Canvas").getComponent(h.default).onSetOwnDiamond(!0),
                t.action()
            });
        }
        var e = g.BaseStorage.getInt(_.BaseStorageKey.RedDotDailyTask, 0) - 1;
        e < 0 && (e = 0),
        g.BaseStorage.setInt(_.BaseStorageKey.RedDotDailyTask, e)
    },
    e.prototype.action = function() {
        p.default.getInstance().SendMessage(d.Broadcast_Func.Audio, d.Audio_ID.get_gold);
        for (var t = 0; t < 20; t++) {
            var e = cc.instantiate(this.prefab),
            o = this.getEndPosOfNode(this.taskType).convertToWorldSpaceAR(cc.Vec2.ZERO),
            i = this.node.getChildByName("icon").convertToNodeSpaceAR(o),
            n = cc.Vec2.ZERO;
            e.setPosition(n),
            e.parent = this.node.getChildByName("icon"),
            e.getComponent(m.default).init(u.Util.getRandomInt(0, 360), u.Util.getRandomInt(200, 400), i, this.iconSpr.spriteFrame)
        }
    },
    e.prototype.getEndPosOfNode = function(t) {
        var e;
        switch (t) {
            case r.sell:
            case r.lottery:
                e = cc.find("Canvas").getChildByName("frame_diamond");
            break;
            case r.victory:
                e = cc.find("Canvas").getChildByName("frame_gold");
        }
        return e
    },
    a([S({
        type: cc.Enum(r)
    })], e.prototype, "taskType", void 0),
    a([S(cc.ProgressBar)], e.prototype, "progress", void 0),
    a([S(cc.Label)], e.prototype, "titleLabel", void 0),
    a([S(cc.Label)], e.prototype, "valueLabel", void 0),
    a([S(cc.Label)], e.prototype, "progressLabel", void 0),
    a([S(cc.Sprite)], e.prototype, "iconSpr", void 0),
    a([S(cc.Prefab)], e.prototype, "prefab", void 0),
    a([S(cc.Node)], e.prototype, "btnNode", void 0),
    a([S(cc.Prefab)], e.prototype, "pfb_boxView", void 0),
    a([S(cc.Node)], e.prototype, "node_finishBtn", void 0),
    a([S(cc.Node)], e.prototype, "statusNode", void 0),
    a([S(C.default)], e.prototype, "dailyTaskBox", void 0),
    a([S(v.default)], e.prototype, "dailyTask", void 0),
    a([S(cc.Float)], e.prototype, "value", void 0),
    a([S(cc.Float)], e.prototype, "totalProgress", void 0),
    a([w], e)
} (cc.Component);
o.default = I